﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jenvin.Library.Utils;
using System.Net;
using System.Web;
using System.Collections.Specialized;
using System.IO;
using Utils.Text;
using Jenvin.Library.Utils.Encryption;
using Utils.DynamicProxy;
namespace Utils
{
    public class LogProxy : IInvocationHandler
    {
        Object obj = null;

        ///<summary>
        /// Class constructor
        ///</summary>
        ///<param name="obj">Instance of object to be proxied</param>
        public LogProxy(Object obj)
        {
            this.obj = obj;
        }
        ///<summary>
        /// IInvocationHandler method that gets called from within the proxy
        /// instance. 
        ///</summary>
        ///<param name="proxy">Instance of proxy</param>
        ///<param name="method">Method instance 
        public Object Invoke(Object proxy, System.Reflection.MethodInfo method, Object[] parameters)
        {
            Object retVal = null;
            Console.WriteLine("pre log");
            retVal = method.Invoke(obj, parameters);
            Console.WriteLine("post log");
            return retVal;
        }
    }

    public interface ITest
    {
        void TestFunctionOne();
        Object TestFunctionTwo(Object a, Object b);
    }

    public class TestImpl : ITest
    {
        public void TestFunctionOne()
        {
            Console.WriteLine("In TestImpl.TestFunctionOne()");
        }

        public Object TestFunctionTwo(Object a, Object b)
        {
            Console.WriteLine("In TestImpl.TestFunctionTwo( Object a, Object b )");
            return null;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
           TestImpl obj=  new TestImpl();
           ITest test = (ITest)ProxyFactory.GetInstance().Create(new LogProxy(obj), obj.GetType());
            test.TestFunctionOne();
            test.TestFunctionTwo(new Object(), new Object());
            return;
            //IHash md5 = HashFactory.CreateMd5();
            //IHash sha1 = HashFactory.CreateSha1();
            //IdentifyEncoding identify = new IdentifyEncoding();
            //String fileName = @"E:\JavaProjects\esearcher\jenvin-util\src\main\java\com\jenvin\util\algorithm\AcStringMatch.java";

            //FileInfo info = new FileInfo(fileName);
            //string encodingName = identify.GetEncodingName(info);

            //var ss = "%e4%b8%93%e7%94%a8%e6%b1%bd%e8%bd%a6%e3%80%81%e8%bd%bb%e5%9e%8b%e6%b1%bd%e8%bd%a6%ef%bc%88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e8%ae%be%e8%ae%a1%e4%b8%8e%e5%bc%80%e5%8f%91%ef%bc%9b%e9%a9%be%e9%a9%b6%e5%91%98%e5%9f%b9%e8%ae%ad%ef%bc%9b%e6%99%ae%e9%80%9a%e8%b4%a7%e8%bf%90%ef%bc%88%e9%99%90%e5%88%86%e5%85%ac%e5%8f%b8%e7%bb%8f%e8%90%a5%ef%bc%89%ef%bc%9b%e7%94%b3%e6%8a%a5%e5%8a%a0%e6%b2%b9%e7%ab%99%e8%b5%84%e8%b4%a8%e3%80%82%0d%0a";
            //var s22 = "专用汽车、轻型汽车（不含小轿车）、低速货车、随车起重机及汽车零部件的制造、销售；金属罐体（含A2、C2三类压力容器）、塑料罐体、化工防腐设备的制造、销售（涉及行政许可的项目须持有效许可证经营）；专用汽";
            //var ss2 = HttpUtility.UrlDecode(ss, Encoding.UTF8);
            HttpClient executor = new HttpClient("127.0.0.1");
            executor.Encode = Encoding.GetEncoding("utf-8");
            //executor.Proxy = new WebProxy("127.0.0.1", 8888);
            executor.AutoRedirect = true;
            executor.CookieContainer = new CookieContainer();

            string ret = executor.PostStringReturnString("http://localhost:8081/Controller/Login", "loginname=jenvin&loginpass=19850418");

            //string s2 = executor.GetString("http://www.ppurl.com/dashboard/");
            //string s3 = executor.GetString("http://www.ppurl.com/dashboard/downloads/");

            //executor.GetFile("http://image.esunny.com/FileFolder/20111123103244.pdf", @"c:\tmp.pdf");

            //NameValueCollection nvFiles = new NameValueCollection();
            //nvFiles.Add("file1", @"c:\bar.emf");
            //nvFiles.Add("file2", @"c:\一个牛人给java初学者的建议.doc");

            //NameValueCollection values = new NameValueCollection();
            //values.Add("name1", "value1,手机");
            //values.Add("name2", "value2，手机=");
            //values.Add("name3", "value3，手机&");
            //values.Add("name4", "value4");
            //executor.Encode = Encoding.GetEncoding("gb2312");
            //string ret = executor.Encode
            //    .GetString(executor.PostValues("http://interface.esunny.com/UploadFile.aspx?action=html", values, nvFiles));

            Console.Write(ret);

            //executor.p
            //Get ,Post

            //
            //executor.Credentials = new NetworkCredential("zhengwen.zhou@eascs.com", "Abc@123");
            /*
           
          
            executor.AutoRedirect = true;
            executor.CookieContainer = new CookieContainer();

            string s = executor.PostString("http://www.ppurl.com/login/", "loginname=jenvin&loginpass=19850418");
            string s2 = executor.GetString("http://www.ppurl.com/dashboard/");
            string s3 = executor.GetString("http://www.ppurl.com/dashboard/downloads/");

           
             * */
            //executor.GetFile("http://image.esunny.com/FileFolder/20111123103244.pdf", @"c:\tmp.pdf");
            //executor.GetFile("http://image.esunny.com//FileFolder/20111123010130.zip", @"c:\1.rar");
            //executor.PostFile("http://interface.esunny.com/UploadFile.aspx?action=html", @"c:\bar.emf");
            //executor.PostFile(""
        }
    }
}
